From 923c2f2dfabb6881bb8fda88023a5cf25452d7f2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Apr 2015 11:58:13 -0700 Subject: [PATCH] Tweak the meaning of HTTP timeouts Previously a timeout was set via libcurl's blanket timeout option, which is a timeout for the entire request. This isn't always what we want, however, as cargo is used on quite a variety of networks. Instead what we really want is timing out data being received, so instead of a blanket timeout we set two different timeouts: * The connect timeout is now configured (time it takes to connect the socket) * A "low speed" timeout is now also set. This means that if Cargo doesn't receive 10 bytes of data in the specified tiemout period that the entire transfer will be timed out. Closes #1560 --- Cargo.lock | 4 ++-- src/cargo/ops/registry.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8b5af4dc..a7819cdd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,7 +148,7 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libssh2-sys 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "libssh2-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -164,7 +164,7 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.1.19" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index bae8643c0..7bd22b360 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -166,13 +166,21 @@ pub fn registry(config: &Config, /// Create a new HTTP handle with appropriate global configuration for cargo. pub fn http_handle(config: &Config) -> CargoResult { - let handle = http::handle().timeout(60_000); + // The timeout option for libcurl by default times out the entire transfer, + // but we probably don't want this. Instead we only set timeouts for the + // connect phase as well as a "low speed" timeout so if we don't receive + // many bytes in a large-ish period of time then we time out. + let handle = http::handle().timeout(0) + .connect_timeout(30_000 /* milliseconds */) + .low_speed_limit(10 /* bytes per second */) + .low_speed_timeout(30 /* seconds */); let handle = match try!(http_proxy(config)) { Some(proxy) => handle.proxy(proxy), None => handle, }; let handle = match try!(http_timeout(config)) { - Some(timeout) => handle.timeout(timeout as usize), + Some(timeout) => handle.connect_timeout(timeout as usize) + .low_speed_timeout((timeout as usize) / 1000), None => handle, }; Ok(handle) -- 2.30.2